from django import template
from ..models import TeamMemberShip

register = template.Library()


@register.simple_tag(takes_context=True)
def member_class(context, membership):
    current_user = context.get('user', None)
    classes = ['member']

    if isinstance(membership, TeamMemberShip):
        if membership.role == 'owner':
            classes.append('owner')
        elif membership.role == 'admin':
            classes.append('admin')

        if current_user and membership.member == current_user:
            classes.append('me')
    else:
        classes.append('inactive')

    return ' '.join(classes)


